﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace Megaman
{
    class BackgroundMusic
    {

        float intro_length;
        public Song intro;
        public Song loop;
        float elapsed;
        public bool introPlaying = false;
       public  bool loopPlaying = false;

        public BackgroundMusic(float intro_length, Song intro, Song loop)
        {
            elapsed = 0;
            this.intro_length = intro_length;
            this.loop = loop;
            this.intro = intro;

        }

        public void Update(GameTime gametime)
        {
            if (!introPlaying && !loopPlaying)
            {
                MediaPlayer.Play(intro);
                introPlaying = true;
                return;
            }

            elapsed += (float)gametime.ElapsedGameTime.TotalSeconds;

            if (elapsed >= intro_length)
            {
                introPlaying = false;
                loopPlaying = true;
            }

            if (loopPlaying && MediaPlayer.State == MediaState.Stopped)
            {

                MediaPlayer.IsRepeating = true;

                //MediaPlayer.Stop();
                MediaPlayer.Play(loop);
            }

        }
    }
}
